package lib.Dao;

import lib.Model.School;

import java.sql.*;
import java.util.List;
import java.util.ArrayList;


public class SchoolDAO {
    public List<School> getSchool() throws SQLException{
        Statement stmt = null;
        Dbutil dbutil = new Dbutil();
        Connection con = null;
        ResultSet rs = null;
        List<School> list =new ArrayList<>();

         try{
            con = dbutil.getCon();
            stmt = con.createStatement();
            String sql = "select * from school_list;";
            rs = stmt.executeQuery(sql);
            while(rs.next()) {
              School School=new School(rs.getInt("sid"),rs.getString("sname"),rs.getString("se"));
              list.add(School);

            }
            return list;
        }catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<School> getSchoollike(String content) throws SQLException{
        Statement stmt = null;
        Dbutil dbutil = new Dbutil();
        Connection con = null;
        ResultSet rs = null;
        List<School> list =new ArrayList<>();

        try{
            con = dbutil.getCon();
            PreparedStatement pst = null;
            //System.out.println(content);
            stmt = con.createStatement();
            // INSERT INTO Student(sId,sName) VALUES (?,?)  "delete from notes where notes_id = ?";

            String sql = "select * from school_list where sname like  "+"'%"+content+"%'";
            //pst = con.prepareStatement(sql);
            //pst.setString(1,content);
            //System.out.println(sql);
            rs =stmt.executeQuery(sql);

            while(rs.next()) {
                School School=new School(rs.getInt("sid"),rs.getString("sname"),rs.getString("se"));
                list.add(School);

            }
            return list;
        }catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }


}
